<?php 

class phan_trang
{
	function lay_trang_hien_tai()
	{
		
		if(isset($_GET['page'])){
			$page = $_GET['page'];
		}else{
			$page = 1;
		}
		
		return $page;	
	}
	
	function tim_trang_bat_dau($page, $mau_tin)
	{
		
		$start = ($page - 1)*$mau_tin;
		return $start;
	}
	
	function tong_so_trang($tong_so_dong, $mau_tin)
	{
		
		$tong = ceil($tong_so_dong/$mau_tin);
		return $tong;	
	}
	
	function page_list($page, $tong,$vitri)
	{
		#Tên file
			$ten_file = $_SERVER['PHP_SELF'];
			$tham_so = $_SERVER['QUERY_STRING'];
			$tham_so = str_replace('&page='.$page,'',$tham_so);//Có tham số
			$tham_so = str_replace('page='.$page,'',$tham_so);// Không có tham số
			if($tham_so != '')
			{
				$tham_so = $tham_so.'&';	
			}
			
		#Về đầu trang
			if($page > 1)
			{
				$first = 1;
				echo "<a class='page' href='$ten_file?{$tham_so}page=$first'>First</a>";
			}else
			{
				echo "<a class='page disable'>First</a>";
			}
			
			#Về trang trước
			if($page > 1)
			{
				$back = $page-1;
				echo "<a class='page' href='$ten_file?{$tham_so}page=$back'>Back</a>";
			}else
			{
				echo "<a class='page disable'>Back</a>";	
			}
			
					
			# vị trí đầu
			$vtdau = max($page-$vitri, 1);
			
			# Vị trí sau
			$vtsau = min($page+$vitri, $tong);
			
			#In bộ nút
			if($vtdau > 1)
			{
				echo '<b style="text-decoration:none;color:#F99">...</b>';
			}
			for ($i = $vtdau; $i <= $vtsau; $i++)
			{
				if($page == $i)
				{
					echo "<a class='page current'>$i</a>";	
				}else
				{
					echo "<a class='page ' href='$ten_file?{$tham_so}page=$i'>$i</a>";	
				}
				
			}
			if($vtsau < $tong)
			{
				echo '<b class="page">...</b>';
			}
			#Về trang sau
			if($page < $tong)
			{
				$next = $page+1;
				echo "<a class='page' href='$ten_file?{$tham_so}page=$next'>Next</a>";
			}else
			{
				echo "<a class='page disable'>Next</a>";
			}
			
			#Về cuối trang
			if($page < $tong)
			{
				$last = $tong;
				echo "<a class='page' href='$ten_file?{$tham_so}page=$tong'>Last</a>";
			}else
			{
				echo "<a class='page disable'>Last</a>";
			}
			
			
		
	}
	
	
}









?>
